<?php
class Zendvn_Recursive{
	
	private $_data;
	
	public function __construct($data = null){
		$this->_data = $data;
	}
	
	public function process($parent = 0){
		$newMenu = array();
		$this->recursive($this->_data,$parent,1,$newMenu);
		return $newMenu;
	}
	
	public function recursive($menu,$parent = 0,$level = 1,&$newMenu){
		foreach ($menu as $key => $val){
			if($val['parent'] == $parent){
				$val['level'] = $level;
				$newMenu[] = $val;
				unset($menu[$key]);
				$this->recursive($menu,$val['id'],$val['level'] + 1,$newMenu);
			}
		}
	}
	public function getparentIdArray($id,$options = null){
		if($options['type'] == 1){
			$arrparent[] = $id;
		}
		$this->findparent($this->_data,$id, &$arrparent);
		return $arrparent;
	}
	
	public function findparent($sourceArr,$id, &$arrparent){
		foreach ($sourceArr as $key => $value){
			if($value['id'] == $id){
				if( $value['parent'] >0 ){
					$arrparent[] = $value['parent'];
					unset($sourceArr[$key]);
					$newID = $value['parent'];
					$this->findparent($sourceArr,$newID, $arrparent);
				}
			}
		}
	}
}